<?php
/**
 * Created by PhpStorm.
 * User: smilezheng
 * Date: 2019/9/2
 * Time: 16:10
 */

namespace Test\Controller;

use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\PHPMailer;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

class TestSendEmail extends KernelTestCase
{
    public function testSomeMethod()
    {
        try {
            $mail = new PHPMailer();
            assert($mail instanceof PHPMailer);
            $mail->SMTPDebug = 2;                                       // Enable verbose debug output
            $mail->isSMTP();                                            // Set mailer to use SMTP
            $mail->Host       = 'smtp.qq.com';                          // Specify main and backup SMTP servers
            $mail->SMTPAuth   = true;                                   // Enable SMTP authentication
            $mail->Username   = '1486145487@qq.com';                     // SMTP username
            $mail->Password   = 'nivkribdtpwsgcac';                     // SMTP password
            $mail->SMTPSecure = 'ssl';                                  // Enable TLS encryption, `ssl` also accepted
            $mail->Port       = 465;                                    // TCP port to connect to

            //Recipients
            $mail->setFrom('1486145487@qq.com', 'Mailer');

            $mail->addAddress('1486145487@qq.com', 'Joe User');     // Add a recipient
            $mail->addAddress('1486145487@qq.com');               // Name is optional
            $mail->addReplyTo('1486145487@qq.com', 'Information');
            $mail->addCC('1486145487@qq.com');
            $mail->addBCC('bcc@example.com');

            // Attachments
            //        $mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
            //        $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name

            // Content
            $mail->isHTML(true);                                  // Set email format to HTML
            $mail->Subject = 'Here is the subject';
            $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
            $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

            $mail->send();
        } catch (Exception $e) {
            echo "发送异常";
        }
    }
}